package thead;

/*
提供：可以通过 synchronized 或者 Lock 来实现一个死锁代码。



所谓的死锁就是线程一拥有锁1，线程二拥有锁2，双方在拥有自身锁的同时尝试获取对方的锁，最终两个线程就会进入无线等待的状态，这就是死锁。
 */
public class practice5_3 {
    public static final Object lock1= new Object();
    public static final Object lock2= new Object();
    public static void main(String[] args) {
        Thread t1 = new Thread(() ->{
            synchronized (lock1) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                synchronized(lock2) {
                }
            }
        });
        Thread t2 = new Thread(() ->{
            synchronized (lock2) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                synchronized (lock1) {
                }
            }
        });
        t1.start();
        t2.start();

    }
}
